package com.yzh.pethome.controller;

import com.yzh.pethome.domain.PageList;
import com.yzh.pethome.domain.PageParams;
import com.yzh.pethome.pojo.Dept;
import com.yzh.pethome.service.DeptService;
import org.apache.ibatis.annotations.Delete;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/dept")
//@CrossOrigin
public class DeptController {
    @Autowired
    private DeptService deptService;
    @RequestMapping("/selectAllDept")
    public List<Dept> selectAllDept(){
        return deptService.selectAllDept();
    }
    @RequestMapping("/addDept")
    public void addDept(@RequestBody Dept dept){
        deptService.addDept(dept);
    }
    @RequestMapping("/deleteDept")
    public void deleteDept(@RequestParam("id") Long id){
        deptService.deleteDept(id);
    }

    @RequestMapping("/updateDept")
    public void updateDept(@RequestBody Dept dept){
        deptService.updateDept(dept);
    }
    @RequestMapping("/selectDeptById")
    public Dept selectDeptById(@RequestParam("id") Long id){
        return deptService.selectDeptById(id);
    }

    @RequestMapping("/selectDeptByPage")
    public PageList<Dept> selectDeptByPage(@RequestBody PageParams pageParams){
        // 参数校验
        if (pageParams.getPageNum() == null || pageParams.getPageNum() <= 0) {
            pageParams.setPageNum(1);
        }
        if (pageParams.getPageSize() == null || pageParams.getPageSize() <= 0) {
            pageParams.setPageSize(10);
        }
        return deptService.selectDeptByPage(pageParams);
    }



}
